<?php
ini_set("session.cookie_domain", ".wnyhsports.com");
$CONFIG['site'] = "beta.wnyhsports.com";
include("inc/config.php");
if(isset($_GET['team'])){
	$_SESSION['team'] = $_GET['team'];
	gotopage("index.php");
}
if(isset($_GET['cteam'])){
	$_SESSION['team'] = NULL;
	gotopage("index.php");
}
$_SESSION['username'] = 'joey';
if($_SERVER['HTTP_HOST'] == "teamcontrol.wnyhsports.com"){
	$_SESSION['location'] = 'teamcontrol';
}else{
	$_SESSION['team'] = NULL;
	$_SESSION['location'] = 'home';
}
if(isset($_POST['username'])){
	$sql = "SELECT * FROM `amember_members` WHERE `login` = :username";
	$q = db::Query($sql, array(':username'=>$_POST['username']));
	$row = $q->fetch();
	if($row['pass'] == $_POST['password'] and ($row['status'] == 1 or $row['status'] == 2)){
		$_SESSION['username'] = $_POST['username'];
	}else{
		if($row['status'] == 0){
			$LoginErr = "Your Account Has a Balance Due";
		}elseif($row['status'] == 2){
			$LoginErr = "Your Account Subscription Has Expired";
		}else{
			$LoginErr = "Your Username/Password is Incorrect";
		}
	}
}
if(isset($_SESSION['username'])){
	$sql = "SELECT * FROM `amember_members` WHERE `login` = :username";
	$q = db::Query($sql, array(':username'=>$_SESSION['username']));
	$row = $q->fetch();
	foreach($row as $key=>$value){
		$USER[$key] = $value;
	}
	
	if($_SESSION['location'] == 'teamcontrol'){
		$sql = "SELECT * FROM  `teams` WHERE `member_id` = :mem";
		$q = db::Query($sql, array(':mem'=>$USER['member_id']));
		while($row = $q->fetch()){
			$TEAMS[$row['team_id']] = $row;
		}
		if(isset($_SESSION['team'])){
			$sql = "SELECT * FROM `sports` WHERE `sport_id` = :id";
			$q = db::Query($sql, array(':id'=>$TEAMS[$_SESSION['team']]['sport_id']));
			$r = $q->fetch();
			$SPORT = $r;
		
			$sql = "SELECT * FROM `schools` WHERE `school_id` = :id";
			$q = db::Query($sql, array(':id'=>$TEAMS[$_SESSION['team']]['school_id']));
			$r2 = $q->fetch();
			$SCHOOL = $r2;		
		}
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>WNYHSports.com</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/menu.css" rel="stylesheet" type="text/css" />
<link href="css/layout.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="css/slide.css" type="text/css" media="screen" />
<link rel="stylesheet" type="text/css" media="all" href="css/sexyalertbox.css"/>
<link rel="stylesheet" type="text/css" media="all" href="css/jquery.timepickr.css"/>
<link rel="stylesheet" type="text/css" media="all" href="css/jquery.tooltip.css"/>
<link rel="stylesheet" type="text/css" media="all" href="css/nivo-slider.css" />
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
<script type="text/javascript" src="http://jquery-utils.googlecode.com/svn/trunk/src/jquery.anchorHandler.js"></script>
<script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="js/sexyalertbox.v1.2.jquery.js"></script>
<script src="js/slide.js" type="text/javascript"></script>
<script src="js/jquery.nivo.slider.pack.js" type="text/javascript"></script>
<?php if(isset($LoginErr)){ ?>
<script>
$(document).ready(function() {
	$("div#panel").slideDown("slow");	
	$("#toggle a").toggle();
});
</script>
<?php } ?>
<?php if($_SESSION['location'] == 'teamcontrol' and count($TEAMS) > 1 and $_SESSION['team'] == NULL){ ?>
<script>
function verifyNewTeamForm(){
	if(document.getElementById('newteamSchool').options[document.getElementById("newteamSchool").selectedIndex].value == 'Select One...'){
		alert("You Must Select A School");
		return false;
	}else if(document.getElementById('newteamSport').options[document.getElementById("newteamSport").selectedIndex].value == 'Select One...'){
		alert("You Must Select A Sport");
		return false;
	}else if(document.getElementById('newteamGender').options[document.getElementById("newteamGender").selectedIndex].value == 'Select One...'){
		alert("You Must Select A Team Gender");
		return false;
	}else{
		document.forms["newteamForm"].submit();
		return true;
	}
}

$(document).ready(function() {
	<?php if(!isset($_GET['ateam'])){ ?>
	Sexy.info("<style>#BoxAlertBtnOk{display:none;}</style>Please Select A Team To Manage:<br/><br/><select style='width:98%' id='team' onchange='window.location = \"index.php?team=\"+document.getElementById(\"team\").options[document.getElementById(\"team\").selectedIndex].value'><option>Select One...</option><?php foreach($TEAMS as $value){ ?><?php $sql = "SELECT * FROM `sports` WHERE `sport_id` = :id"; $q = db::Query($sql, array(':id'=>$value['sport_id']));$r = $q->fetch(); $sql = "SELECT * FROM `schools` WHERE `school_id` = :id"; $q = db::Query($sql, array(':id'=>$value['school_id']));$r2 = $q->fetch(); if($r['sport_name'] != ""){ if($value['gender'] == '0'){$value['gender'] = 'Male';};  if($value['gender'] == '1'){$value['gender'] = 'Female';};  if($value['gender'] == '3'){$value['gender'] = 'Co-Ed';}?><option value='<?php echo $value['team_id'] ?>'><?php echo $value['gender'] ?> <?php echo $r['sport_name'] ?> - <?php echo $r2['school_name'] ?></option><?php };} ?></select><br/><br/><div width='100%' align='right'><input type='button' value='Add New Team' class='NFButton' onclick='window.location = \"index.php?ateam=true\"'> <input type='button' value='Cancel' class='NFButton' onclick='window.location = \"http://beta.wnyhsports.com\"'></div>");
});
	<?php }else{ ?>
	Sexy.info("<style>#BoxAlertBtnOk{display:none;}</style>Fill Out The Following Form To Add A Team:<br/><br/><form action='index.php' method='post' name='newteamForm'><table width='100%' cellspacing='10'><tr><td width='100'>School:</td><td><select style='width:98%' name='school' id='newteamSchool'><option>Select One...</option><?php $sql = "SELECT * FROM `schools` ORDER BY `school_name` ASC"; $q = db::Query($sql); while($r = $q->fetch()){?><option value='<?php echo $r['school_id'] ?>'><?php echo $r['school_name'] ?></option><?php } ?></select></td></tr><tr><td>Sport:</td><td><select style='width:98%' name='sport' id='newteamSport'><option>Select One...</option><?php $sql = "SELECT * FROM `sports`"; $q = db::Query($sql); while($r = $q->fetch()){?><option value='<?php echo $r['sport_id'] ?>'><?php echo $r['sport_name'] ?></option><?php } ?></select></td></tr><tr><td>Team Gender:</td><td><select style='width:98%' name='gender' id='newteamGender'><option>Select One...</option><option>Co-Ed</option><option>Female</option><option>Male</option></select></table></form><br/><div width='100%' align='right'><input type='submit' value='Finish' class='NFButton' onclick='return verifyNewTeamForm();'> <input type='button' value='Cancel' class='NFButton' onclick='window.location = \"http://teamcontrol.wnyhsports.com\"'></div>");
});
	<?php } ?>
</script>
<?php } ?>
<style>
body {
	<?php if($_SESSION['location'] == 'teamcontrol'){ ?>
	background-image:url(images/pattern_036.gif);
	<?php }else{ ?>
	background-image:url(images/pattern_062.gif);
	<?php } ?>
	background-repeat:repeat;
	padding:0px;
}
#header {
	height:auto;
}
.box {
	border:1px #666 solid !important;
	padding-top:0px;
	padding-bottom:10px;
}
#boxContent {
	padding-left: 5px;
	padding-right:5px;
}
.box h3, .box h1 {
	font-size:18px;
	font-family:Arial, Helvetica, sans-serif;
	font-weight:bold;
	color:#000;
	border:none;
	border-bottom:1px #666 solid;
	background-color:#CCC;
	margin-top:0px;
	text-align:center;
	width:auto;
	padding-top:5px;
	padding-bottom:-5px;
}
.box h1 {
	margin-left:-5px;
	margin-right:-5px;
}
</style>
</head>
<body>
<?php include("inc/login.php"); ?>
<div id="header" class="png">
  <div class="row-1">
    <div class="fleft"> <img alt="" height="60" src="images/logo.png" class="png" /> </div>
    <div class="fright"> </div>
  </div>
  <div class="row-2">
  	<?php if($_SESSION['location'] == 'teamcontrol'){ ?>
	    <?php include("inc/navigation_teamcontrol.php"); ?>
    <?php }else{ ?>
    	<?php include("inc/navigation.php"); ?>
    <?php } ?>
  </div>
</div>
<div id="content" <?php if($_SESSION['location'] == 'home'){ ?>align="center"<?php } ?>>
<table width="<?php if($_SESSION['location'] == 'teamcontrol'){ ?>100<?php }else{ ?>50<?php } ?>%" cellspacing="10">
  <tr>
    <td width="<?php if($_SESSION['location'] == 'teamcontrol'){ ?>20<?php }else{ ?>25<?php } ?>%">
	  <?php include("modules/poll.mod.php"); ?>
      <?php if($_SESSION['location'] == 'home'){ ?>
	      <?php include("modules/fallsportsupdates.mod.php"); ?>
      <?php } ?>
    </td>
    <td width="<?php if($_SESSION['location'] == 'teamcontrol'){ ?>57<?php }else{ ?>75<?php } ?>%">